package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectServies;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class NursingProjectServiesImpl implements NursingProjectServies {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> getNursingProject(String name, Integer pageNum, Integer pageSize, Integer status) {
           PageHelper.startPage(pageNum,pageSize);
         Page<NursingProject> nursingProject = nursingProjectMapper.getNursingProject(name, status);
//  使用 PageResponse.of 方法将查询到的 Page<NursingProject> 对象转换为 PageResponse<NursingProjectVo> 对象。
//  NursingProjectVo.class 表示要将 NursingProject 对象转换为 NursingProjectVo 对象。
        PageResponse<NursingProjectVo> projectVoPageResponse = PageResponse.of(nursingProject, NursingProjectVo.class);
        return   projectVoPageResponse;
    }

    @Override
    public void deleteNursingProject(Long id) {
        nursingProjectMapper.deleteNursingProject(id);
    }

    @Override
    public void disableNursingProject(Long id, Integer status) {
        nursingProjectMapper.disableNursingProject(id,status);
    }

    @Override
    public void addNursingProject(NursingProjectDto nursingProjectDto) {
        NursingProject  nursingProject=new NursingProject();
        BeanUtils.copyProperties(nursingProjectDto,nursingProject);
        nursingProjectMapper.addNursingProject(nursingProject);
    }

    @Override
    public NursingProjectVo echoNursingProject(Long id) {
        NursingProject nursingProject=nursingProjectMapper.echoNursingProject(id);
        NursingProjectVo nursingProjectVo=new NursingProjectVo();
        BeanUtils.copyProperties(nursingProject,nursingProjectVo);
           return nursingProjectVo;
    }

    @Override
    public void updateNursingProject(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject=new NursingProject();
        BeanUtils.copyProperties(nursingProjectDto,nursingProject);
        nursingProject.setUpdateTime(LocalDateTime.now());
        nursingProjectMapper.updateNursingProject(nursingProject);
    }

}
